#!/bin/bash

# P1任务演示启动脚本

echo "🚀 启动P1任务演示..."

# 检查Python环境
if ! command -v python3 &> /dev/null; then
    echo "❌ Python3 未安装"
    exit 1
fi

# 检查Docker环境
if ! command -v docker &> /dev/null; then
    echo "❌ Docker 未安装"
    exit 1
fi

# 检查Docker Compose
if ! command -v docker-compose &> /dev/null; then
    echo "❌ Docker Compose 未安装"
    exit 1
fi

echo "✅ 环境检查通过"

# 安装Python依赖
echo "📦 安装Python依赖..."
pip3 install -r requirements-p1.txt

if [ $? -ne 0 ]; then
    echo "❌ 依赖安装失败"
    exit 1
fi

echo "✅ 依赖安装完成"

# 启动监控栈
echo "🐳 启动监控栈..."
docker-compose -f docker-compose.jaeger.yml up -d

if [ $? -ne 0 ]; then
    echo "❌ 监控栈启动失败"
    exit 1
fi

echo "✅ 监控栈启动完成"

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 10

# 运行测试
echo "🧪 运行P1任务测试..."
python3 test_p1_implementation.py

if [ $? -eq 0 ]; then
    echo "✅ 所有测试通过"
else
    echo "❌ 部分测试失败"
fi

# 运行集成示例
echo "🎯 运行集成示例..."
python3 core/integration_example.py

echo ""
echo "🎉 P1任务演示完成！"
echo ""
echo "📊 监控界面访问地址："
echo "  - Jaeger UI: http://localhost:16686"
echo "  - Grafana: http://localhost:3000 (admin/admin)"
echo "  - Prometheus: http://localhost:9090"
echo ""
echo "🛑 停止监控栈: docker-compose -f docker-compose.jaeger.yml down"
